2000W / 48V LLC Battery-Charger  V1.00
xmc_acmp.h
Go to the documentation of this file.
1 
66 #ifndef XMC_ACMP_H
67 #define XMC_ACMP_H
68 
69 
98 /*********************************************************************************************************************
99  * HEADER FILES
100  ********************************************************************************************************************/
101 #include <xmc_common.h>
102 
103 /*********************************************************************************************************************
104  * MACROS
105  ********************************************************************************************************************/
106 /* If ACMP is available*/
107 #if defined (COMPARATOR)
108 
109 #define XMC_ACMP0 (XMC_ACMP_t*)COMPARATOR
111 #if UC_SERIES == XMC14
112 #define XMC_ACMP_MAX_INSTANCES (4U) /* Maximum number of Analog Comparators available*/
113 #else
114 #define XMC_ACMP_MAX_INSTANCES (3U) /* Maximum number of Analog Comparators available*/
115 #endif
116 
117 /* Checks if the pointer being passed is valid*/
118 #define XMC_ACMP_CHECK_MODULE_PTR(PTR) (((PTR)== (XMC_ACMP_t*)COMPARATOR))
119 
120 /* Checks if the instance being addressed is valid*/
121 #define XMC_ACMP_CHECK_INSTANCE(INST) (((INST)< XMC_ACMP_MAX_INSTANCES))
122 
123 /*********************************************************************************************************************
124  * ENUMS
125  ********************************************************************************************************************/
126 
130 typedef enum XMC_ACMP_STATUS
131 {
132  XMC_ACMP_STATUS_SUCCESS = 0U,
133  XMC_ACMP_STATUS_ERROR ,
134 } XMC_ACMP_STATUS_t;
135 
139 typedef enum XMC_ACMP_HYSTERESIS
140 {
141  XMC_ACMP_HYSTERESIS_OFF = 0U,
142  XMC_ACMP_HYSTERESIS_10 ,
143  XMC_ACMP_HYSTERESIS_15 ,
144  XMC_ACMP_HYSTERESIS_20
145 } XMC_ACMP_HYSTERESIS_t;
146 
150 typedef enum XMC_ACMP_COMP_OUT
151 {
152  XMC_ACMP_COMP_OUT_NO_INVERSION = 0U,
154  XMC_ACMP_COMP_OUT_INVERSION
156 } XMC_ACMP_COMP_OUT_t;
157 
161 typedef enum XMC_ACMP_INP_SOURCE
162 {
163  XMC_ACMP_INP_SOURCE_STANDARD_PORT = 0U,
164  XMC_ACMP_INP_SOURCE_ACMP1_INP_PORT = (uint16_t)(COMPARATOR_ANACMP0_ACMP0_SEL_Msk)
166 } XMC_ACMP_INP_SOURCE_t;
167 
168 /*********************************************************************************************************************
169  * DATA STRUCTURES
170  ********************************************************************************************************************/
171 
172 
173 /*Anonymous structure/union guard start*/
174 #if defined(__CC_ARM)
175  #pragma push
176  #pragma anon_unions
177 #elif defined(__TASKING__)
178  #pragma warning 586
179 #endif
180 
184 typedef struct {
185  __IO uint32_t ORCCTRL;
186  __I uint32_t RESERVED[726];
187  __IO uint32_t ANACMP[XMC_ACMP_MAX_INSTANCES];
188 } XMC_ACMP_t;
189 
193 typedef struct XMC_ACMP_CONFIG
194 {
195  union
196  {
197  struct
198  {
199  uint32_t : 1;
200  uint32_t filter_disable : 1;
202  uint32_t : 1;
203  uint32_t output_invert : 1;
204  uint32_t hysteresis : 2;
206  uint32_t : 26;
207  };
208  uint32_t anacmp;
209  };
210 } XMC_ACMP_CONFIG_t;
211 
212 /*Anonymous structure/union guard end*/
213 #if defined(__CC_ARM)
214  #pragma pop
215 #elif defined(__TASKING__)
216  #pragma warning restore
217 #endif
218 
219 #ifdef __cplusplus
220  extern "C" {
221 #endif
222 
223 /*********************************************************************************************************************
224  * API Prototypes
225  ********************************************************************************************************************/
226 
246 void XMC_ACMP_Init(XMC_ACMP_t *const peripheral, uint32_t instance, const XMC_ACMP_CONFIG_t *const config);
247 
267 __STATIC_INLINE void XMC_ACMP_EnableComparator(XMC_ACMP_t *const peripheral, uint32_t instance)
268 {
269  XMC_ASSERT("XMC_ACMP_EnableComparator:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
270  XMC_ASSERT("XMC_ACMP_EnableComparator:Wrong instance number", XMC_ACMP_CHECK_INSTANCE(instance) )
271 
272  peripheral->ANACMP[instance] |= (uint16_t)COMPARATOR_ANACMP0_CMP_EN_Msk;
273 
274 }
275 
276 
294 __STATIC_INLINE void XMC_ACMP_DisableComparator(XMC_ACMP_t *const peripheral, uint32_t instance)
295 {
296  XMC_ASSERT("XMC_ACMP_DisableComparator:Wrong module pointer", XMC_ACMP_CHECK_MODULE_PTR(peripheral))
297  XMC_ASSERT("XMC_ACMP_DisableComparator:Wrong instance number", XMC_ACMP_CHECK_INSTANCE(instance) )
298 
299  peripheral->ANACMP[instance] &= (uint16_t)(~((uint32_t)COMPARATOR_ANACMP0_CMP_EN_Msk));
300 }
301 
315 __STATIC_INLINE void XMC_ACMP_EnableReferenceDivider(void)
316 {
317  /* Enable the divider switch and connect the divided reference to ACMP1.INP */
318  COMPARATOR->ANACMP1 |= (uint16_t)(COMPARATOR_ANACMP1_REF_DIV_EN_Msk);
319 }
320 
334 __STATIC_INLINE void XMC_ACMP_DisableReferenceDivider(void)
335 {
336  /* Disable the divider switch and use ACMP1.INP as standard port*/
337  COMPARATOR->ANACMP1 &= (uint16_t)(~(COMPARATOR_ANACMP1_REF_DIV_EN_Msk));
338 }
339 
370 void XMC_ACMP_SetInput(XMC_ACMP_t *const peripheral, uint32_t instance, const XMC_ACMP_INP_SOURCE_t source);
371 
372 
387 __STATIC_INLINE void XMC_ACMP_SetLowPowerMode(void)
388 {
389  COMPARATOR->ANACMP0 |= (uint16_t)COMPARATOR_ANACMP0_CMP_LPWR_Msk;
390 }
391 
405 __STATIC_INLINE void XMC_ACMP_ClearLowPowerMode(void)
406 {
407  COMPARATOR->ANACMP0 &= (uint16_t)(~(uint16_t)COMPARATOR_ANACMP0_CMP_LPWR_Msk);
408 }
409 
418 #ifdef __cplusplus
419 }
420 #endif
421 
422 #endif /* If ACMP is available*/
423 
424 #endif /* XMC_ACMP_H */
#define COMPARATOR_ANACMP0_CMP_LPWR_Msk
Definition: XMC1400.h:4686
#define COMPARATOR_ANACMP1_REF_DIV_EN_Msk
Definition: XMC1400.h:4700
#define __I
Definition: core_cm0.h:162
#define XMC_ASSERT(msg, exp)
Definition: xmc_common.h:132
#define __IO
Definition: core_cm0.h:165
#define COMPARATOR_ANACMP0_ACMP0_SEL_Msk
Definition: XMC1400.h:4684
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
#define COMPARATOR_ANACMP0_CMP_EN_Msk
Definition: XMC1400.h:4676
#define COMPARATOR
Definition: XMC1400.h:8843